home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / BF_SDK11.ZIP / PASCAL.TXT < prev   
Text File  |  1996-06-10  |  9KB  |  198 lines

  1.  
  2.                                     BF-SDK
  3.                                     ~~~~~~
  4.                                      V1.1
  5.  
  6.                                Pascalinterface
  7.                                ~~~~~~~~~~~~~~~
  8.  
  9.                     (c) 1996 Cedric Reinartz & Markus Hahn
  10.  
  11.  
  12. This documentation helps you to use the pascal interface in your own 
  13. program. You need to include the unit BLOWFISH.TPU in your programm. 
  14. It should be sufficient to use the provided one which was compiled with
  15. the default parameters. For changing the parameters please see ASM.TXT.
  16.  
  17. The following type declarations are made in BLOWFISH.TPU:
  18.  
  19.   ULONG = Longint;     { unsigned 32bit }
  20.   UINT  = Word;        { unsigned 16bit }
  21.   UCHAR = Byte;        { unsigned 8bit }
  22.   BOOL  = Word;        { 16bit boolean }
  23.   P_UCHAR_Buffer = ^T_UCHAR_Buffer;
  24.   T_UCHAR_Buffer = array[0..MAXDATA-1] of UCHAR;
  25.   P_UINT_Buffer  = ^T_UINT_Buffer;
  26.   T_UINT_Buffer  = array[0..(MAXDATA div 2)-1] of UINT;
  27.   P_ULONG_Buffer = ^T_ULONG_Buffer;
  28.   T_ULONG_Buffer = array[0..(MAXDATA div 4)-1] of ULONG;
  29.  
  30. You need this declarations to understand and use the following 
  31. descriptions. See also PAS_DEMO.PAS for reference.
  32.  
  33.  
  34.  
  35. Functions
  36. ~~~~~~~~~
  37.  
  38. Blowfish_Init(pKey : P_UCHAR_Buffer; unKeySize : UINT);
  39.  
  40.  Function   : Initialises the Boxes
  41.  Argument   : Pointer to the Password (which is NOT a string)
  42.               Length of the Password
  43.  Return     : none
  44.  Description: A Password with a maximum of 56 Bytes is used to encrypt the
  45.               Boxes. These encrypted boxes are vital for the further encryption
  46.               process with Blowfish_(CBC)Encrypt and Blowfish_(CBC)Decrypt.
  47.               If you want to change the password at runtime you have to restore
  48.               the original contents of the boxes before you can use this
  49.               function again (See Blowfish_GetBoxes and Blowfish_SetBoxes).
  50.  
  51. -------------------------------------------------------------------------------
  52.  
  53. Blowfish_WeakKey : BOOL;
  54.  
  55.  Function   : Test if the generated Boxes are weak
  56.  Argument   : none
  57.  Return     : Status (1=weak, 0=good)
  58.  Description: After "Blowfish_InitCrypt" you should test the Boxes with this 
  59.               function. If they provide a weakness which a cryptoanalyst could
  60.               use to break the cipher a "1" is returned. In this case you
  61.               should reload the original boxes and let the user choose a
  62.               different password.
  63.  
  64. -------------------------------------------------------------------------------
  65.  
  66. Blowfish_ECBEncrypt(pBuffer : P_ULONG_Buffer; unCount : UINT);
  67.  
  68.  Function   : Encrypts a plaintext string using the ECB method
  69.  Argument   : Pointer to the plaintext
  70.               Length of the plaintext
  71.  Return     : none
  72.  Description: This function encrypts (multiple) blocks of 8 Bytes of plaintext
  73.               using the ECB method (blocks are not chained). The generated 
  74.               ciphertext will overwrite the plaintext. Thus the plaintext-
  75.               pointer will point to the ciphertext after the encryption. The 
  76.               length of the plaintext must be a multiple of 8. If it is not,
  77.               plaintext bytes will be left at the end of the ciphertext.
  78.  
  79. -------------------------------------------------------------------------------
  80.  
  81. Blowfish_ECBDecrypt(pBuffer : P_ULONG_Buffer; unCount : UINT);
  82.  
  83.  Function   : Decrypts a ciphertext string using the ECB method
  84.  Argument   : Pointer to the ciphertext
  85.               Length of the ciphertext
  86.  Return     : none
  87.  Description: This function decrypts (multiple) blocks of 8 Bytes of cipher-
  88.               text using the ECB method (blocks are not chained). The generated
  89.               plaintext will overwrite the ciphertext. Thus the ciphertext-
  90.               pointer will point to the plaintext after the decryption. The 
  91.               length of the ciphertext must be a multiple of 8. If it is not, 
  92.               ciphertext bytes will be left at the end of the plaintext.
  93.  
  94. -------------------------------------------------------------------------------
  95.  
  96. Blowfish_CBCEncrypt(pBuffer : P_ULONG_Buffer; unCount : UINT;
  97.                               var ulCBCLeft, ulCBCRight : ULONG);
  98.  
  99.  Function   : Encrypts a plaintext string using the CBC method
  100.  Argument   : Pointer to the plaintext
  101.               Length of the plaintext
  102.               Lower part of the IV
  103.               Upper part of the IV
  104.  Return     : none
  105.  Description: This function encrypts (multiple) blocks of 8 Bytes of plaintext
  106.               using the CBC method (blocks are chained using an initialisation
  107.           vector IV). The generated ciphertext will overwrite the plain-
  108.           text. Thus the plaintext-pointer will point to the ciphertext 
  109.           after the encryption. The length of the plaintext must be a
  110.           multiple of 8. If it is not, plaintext bytes will be left at the
  111.           end of the ciphertext. The IV must not be secret. For different
  112.           encryptions you can choose the same IV but if possible you should
  113.           use different ones to improve security. 
  114.           Note: you need the original IV for decryption.
  115.  
  116.  
  117. -------------------------------------------------------------------------------
  118.  
  119. Blowfish_CBCDecrypt(pBuffer : P_ULONG_Buffer; unCount : UINT;
  120.                               var ulCBCLeft, ulCBCRight : ULONG);
  121.  
  122.  Function   : Decrypts a ciphertext string using the CBC method
  123.  Argument   : Pointer to the ciphertext
  124.               Length of the ciphertext
  125.               Lower part of the IV
  126.               Upper part of the IV
  127.  Return     : none
  128.  Description: This function decrypts (multiple) blocks of 8 Bytes of ciphertext
  129.               using the CBC method (blocks are chained using an initialisation
  130.           vector IV). The generated plaintext will overwrite the cipher-
  131.           text. Thus the ciphertext-pointer will point to the plaintext 
  132.           after the decryption. The length of the ciphertext must be a
  133.           multiple of 8. If it is not, ciphertext bytes will be left at the
  134.           end of the plaintext.
  135.           Note: The IV is the same used on encryption.
  136.  
  137. -------------------------------------------------------------------------------
  138.  
  139. Blowfish_Done;
  140.  
  141.  Function   : Clears the Boxes
  142.  Argument   : none
  143.  Return     : none
  144.  Description: Clears the contents of the P- and S-Boxes. This should be used
  145.               before you exit your program to make sure that no one can get
  146.               your Key.
  147.  
  148. -------------------------------------------------------------------------------
  149.  
  150. Blowfish_SetRounds(Rounds : UINT): UINT;
  151.  
  152.  Function   : Set number of rounds. Returns number of rounds.
  153.  Argument   : # of rounds = 16, 32 or 2-32. See variable RNDS in ASM.TXT
  154.  Return     : number of rounds
  155.  Description: You always have to give a Argument. If BFENG386.ASM was compiled
  156.               with "rnds equ 3" you are able to set the number of rounds 
  157.               between 2 and 32. This function always returns the number of
  158.               rounds actual used. If you supply an invalid argument nothing
  159.               is changed and the currently used number of rounds is returned.
  160.               For more details see variable RNDS in ASM.TXT.
  161.  
  162. -------------------------------------------------------------------------------
  163.  
  164. Blowfish_GetBoxes(pBuffer : P_ULONG_Buffer);
  165.  
  166.  Function   : Copies the actual P- and S-Boxes to a user buffer
  167.  Arguments  : Pointer to the user buffer
  168.  Return     : none
  169.  Description: Use this to save the original Boxes. If you want to change the
  170.               Password at runtime you have to restore these Boxes first. 
  171.               You can also save the encrypted Boxes and restore them if needed.
  172.               In this way you are able to swap Passwords at high speed.
  173.               The needed buffer size is 1042 for rnds=1 and 1058 for rnds=2 or 
  174.               rnds=3 (see ASM.TXT for the meaning of "rnds").
  175.  
  176. -------------------------------------------------------------------------------
  177.  
  178. Blowfish_SetBoxes(pBuffer : P_ULONG_Buffer);
  179.  
  180.  Function   : Copies a user buffer to the P- and S-Boxes
  181.  Arguments  : Pointer to the user buffer
  182.  Return     : none
  183.  Description: Use this to restore the Boxes with previously saved ones.
  184.               See description of "Blowfish_GetBoxes".
  185.  
  186. -------------------------------------------------------------------------------
  187.  
  188. Blowfish_GetBoxPointer : Pointer;
  189.  
  190.  Function   : Returns a Pointer to the beginning of PBox in DX:AX
  191.  Arguments  : none
  192.  Return     : pointer to the Boxes
  193.  Description: For a reason I do not know the pointer is sometimes wrong,
  194.               so verify this! Normaly there is no need to use this function.
  195.  
  196.  
  197. - eof -
  198.